package com.emapp.lccode.activity

import android.app.DatePickerDialog.OnDateSetListener
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.DatePicker
import androidx.fragment.app.Fragment
import com.emapp.lccode.R
import com.emapp.lccode.adapter.ViewPgerKtAdapter
import com.emapp.lccode.base.BaseActivity1
import com.emapp.lccode.base.EventBusConfig
import com.emapp.lccode.base.EventBusModel
import com.emapp.lccode.bean.DeviceKt
import com.emapp.lccode.databinding.ActivityReportBinding
import com.emapp.lccode.fragment.ProjectProgressAddKtFragment
import com.emapp.lccode.utils.setOnclickNoRepeat
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.gyf.immersionbar.ktx.immersionBar
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

/**
 * 进度编辑
 */
class ProgressEditActivity : BaseActivity1<BaseViewModel, ActivityReportBinding>(){
    var titles: ArrayList<String> = arrayListOf("进度上报")
    var fragments: ArrayList<Fragment> = arrayListOf(ProjectProgressAddKtFragment.newInstance(""))
    private val adapter: ViewPgerKtAdapter by lazy { ViewPgerKtAdapter(this, fragments) }
    override fun initView(savedInstanceState: Bundle?) {
        immersionBar {
            titleBar(mViewBind.lvTitle.ivBar)
            statusBarDarkFont(true)
            fullScreen(true)
            statusBarColor(R.color.transparent)
            navigationBarColor(R.color.white)
        }
        mViewBind.lvTitle.tvTitle.text = "进度"
        mViewBind.lvTitle.tvRight.visibility = View.GONE
        EventBus.getDefault().register(this)
        mViewBind.viewpager.adapter = adapter
        mViewBind.layoutTab.tabMode = TabLayout.MODE_SCROLLABLE
        TabLayoutMediator(mViewBind.layoutTab, mViewBind.viewpager) { tab, position ->
            tab.text = titles[position]
        }.attach()
        mViewBind.layoutTab.visibility = View.GONE
    }

    override fun createObserver() {
    }


    override fun onDestroy() {
        super.onDestroy()
        EventBus.getDefault().unregister(this)
    }

    override fun onBindViewClick() {
        setOnclickNoRepeat(
            mViewBind.lvTitle.ivLeft,
            mViewBind.lvTitle.tvRight
        ) {
            when (it.id) {
                R.id.iv_left -> {
                    finish()
                }
            }
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    fun onEventMainThread(event: EventBusModel) {
        when (event.type) {
            EventBusConfig.PROJECT_DEVICE -> {
                // infor=event.`object` as DeviceKt
            }

            else -> {}
        }
    }

}
